package authentication;

import javax.security.auth.callback.*;

/**
 * Authorization handler for kerberos login
 * @author pasquale
 *
 */
public class AuthHandler implements CallbackHandler{
	public AuthHandler(String username,String password){
		this.username = username;
		this.password = password;
	}

	@Override
	public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
		for(int i=0;i<callbacks.length;i++){
			if(callbacks[i] instanceof NameCallback){
				NameCallback nc = (NameCallback)callbacks[i];
				nc.setName(username);
			}else if(callbacks[i] instanceof PasswordCallback){
				PasswordCallback pc = (PasswordCallback)callbacks[i];
				pc.setPassword(password.toCharArray());
			}else
				throw new UnsupportedCallbackException(callbacks[i],"Unsupported callback!");	
		}
	}
	
	private String username;
	private String password;
}
